package com.chaoxuan.uebt.utils;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.chaoxuan.uebt.R;

public class CommomDialog3 extends Dialog implements View.OnClickListener{
        private TextView contentTxt1;
        private TextView contentTxt2;
        private TextView contentTxt3;
        private TextView contentTxt4;
        private TextView submitTxt;
        private TextView cancelTxt;

        private Context mContext;
        private String content1,content2,content3,content4;
        private OnCloseListener listener;
        private String positiveName;
        private String negativeName;
        private String title;

        public CommomDialog3(Context context) {
            super(context);
            this.mContext = context;
        }



        public CommomDialog3(Context context, int themeResId, String content1, String content2,String content3,String content4, OnCloseListener listener) {
            super(context, themeResId);
            this.mContext = context;
            this.content1= content1;
            this.content2= content2;
            this.content3= content3;
            this.content4= content4;
            this.listener = listener;
        }



        public CommomDialog3 setTitle(String title){
            this.title = title;
            return this;
        }

        public CommomDialog3 setPositiveButton(String name){
            this.positiveName = name;
            return this;
        }

        public CommomDialog3 setNegativeButton(String name){
            this.negativeName = name;
            return this;
        }

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.layout_dialog3);
            setCanceledOnTouchOutside(false);
            initView();
        }

        private void initView(){
            contentTxt1 = (TextView)findViewById(R.id.content1);
            contentTxt2 = (TextView)findViewById(R.id.content2);
            contentTxt3 = (TextView)findViewById(R.id.content3);
            contentTxt4 = (TextView)findViewById(R.id.content4);

            submitTxt = (TextView)findViewById(R.id.submit);
            submitTxt.setOnClickListener(this);
            cancelTxt = (TextView)findViewById(R.id.cancel);
            cancelTxt.setOnClickListener(this);

            contentTxt1.setText(content1);
            contentTxt2.setText(content2);
            contentTxt3.setText(content3);
            contentTxt4.setText(content4);
            if(!TextUtils.isEmpty(positiveName)){
                submitTxt.setText(positiveName);
            }

            if(!TextUtils.isEmpty(negativeName)){
                cancelTxt.setText(negativeName);
            }

        }

        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.cancel:
                    if(listener != null){
                        listener.onClick(this, false);
                    }
                    this.dismiss();
                    break;
                case R.id.submit:
                    if(listener != null){
                        listener.onClick(this, true);
                    }
                    break;
            }
        }

        public interface OnCloseListener{
            void onClick(Dialog dialog, boolean confirm);
        }
}
